package com.webflux.webflux02.routes;

import com.webflux.webflux02.config.RoutePath;
import com.webflux.webflux02.handler.ProductHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

@Configuration
public class BaseRoutes {

    @Bean
    public RouterFunction<ServerResponse> routers(ProductHandler productHandler) {
        return RouterFunctions.route()
                .GET(RoutePath.hello,productHandler::hello)
                .POST(RoutePath.save,productHandler::save)
                .GET(RoutePath.queryAll,productHandler::queryAll)
                .GET(RoutePath.find,productHandler::findById)
                .PUT(RoutePath.update,productHandler::update)
                .DELETE(RoutePath.delete,productHandler::delete)
                .POST(RoutePath.page,productHandler::findByPage)
                .POST(RoutePath.saveMany,productHandler::saveMany)
                .GET(RoutePath.findAll,productHandler::findAll)
                .build();
    }

}
